package org.dromara.xhlj.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xhlj.domain.vo.XhljActivityAgendaVo;
import org.dromara.xhlj.domain.query.XhljActivityAgendaQuery;
import org.dromara.xhlj.domain.bo.XhljActivityAgendaBo;
import org.dromara.xhlj.crud.service.IXhljActivityAgendaCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * xhlj-crud-活动议程
 *
 * @author yf
 * @date 2024-07-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xhlj/activityAgenda")
public class XhljActivityAgendaCrudController extends BaseController {

    private final IXhljActivityAgendaCrudService xhljActivityAgendaService;

    /**
     * 分页查询活动议程列表
     */
    @SaCheckPermission("xhlj:activityAgenda:list")
    @GetMapping("/list")
    public TableDataInfo<XhljActivityAgendaVo> list(XhljActivityAgendaQuery query, PageQuery pageQuery) {
         return xhljActivityAgendaService.queryPageList(query, pageQuery);
    }

    /**
     * 查询活动议程列表
     */
    @SaCheckPermission("xhlj:activityAgenda:list")
    @GetMapping("/allList")
    public TableDataInfo<XhljActivityAgendaVo> allList(XhljActivityAgendaQuery query) {
        List<XhljActivityAgendaVo> list =  xhljActivityAgendaService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出活动议程列表
     */
    @SaCheckPermission("xhlj:activityAgenda:export")
    @Log(title = "活动议程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XhljActivityAgendaQuery query, HttpServletResponse response) {
        List<XhljActivityAgendaVo> list = xhljActivityAgendaService.queryList(query);
        ExcelUtil.exportExcel(list, "活动议程", XhljActivityAgendaVo.class, response);
    }

    /**
     * 获取活动议程详细信息
     *
     * @param activityAgendaId 主键
     */
    @SaCheckPermission("xhlj:activityAgenda:query")
    @GetMapping("/{activityAgendaId}")
    public R<XhljActivityAgendaVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer activityAgendaId) {
        return R.ok(xhljActivityAgendaService.queryById(activityAgendaId));
    }

    /**
     * 新增活动议程
     */
    @SaCheckPermission("xhlj:activityAgenda:add")
    @Log(title = "活动议程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XhljActivityAgendaBo bo) {
        bo.setCreateBy(Math.toIntExact(LoginHelper.getUserId()));
        return toAjax(xhljActivityAgendaService.insertByBo(bo));
    }

    /**
     * 修改活动议程
     */
    @SaCheckPermission("xhlj:activityAgenda:edit")
    @Log(title = "活动议程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XhljActivityAgendaBo bo) {
        return toAjax(xhljActivityAgendaService.updateByBo(bo));
    }

    /**
     * 删除活动议程
     *
     * @param activityAgendaIds 主键串
     */
    @SaCheckPermission("xhlj:activityAgenda:remove")
    @Log(title = "活动议程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityAgendaIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] activityAgendaIds) {
        return toAjax(xhljActivityAgendaService.deleteWithValidByIds(List.of(activityAgendaIds), true));
    }
}
